<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="albumBar.xsl" />
	<xsl:include href="rss.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<xsl:call-template name="rss">
				<xsl:with-param name="userLogin">
					<xsl:value-of select="response/@user-login" />
				</xsl:with-param>
				<xsl:with-param name="albumId">
					<xsl:value-of select="response/@album-id" />
				</xsl:with-param>
			</xsl:call-template>
			<link rel="stylesheet" href="{$baseURI}/css/photos/photos.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
					
					<xsl:if test="@method = 'album'">
						<div class="block">
							<div class="header">Другие альбомы пользователя</div>
							<div class="content user-photoalbums-list">
								<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbums/', response/@album-owner-id, ';', response/@album-id))/data/response" mode="block-user-albums" />
							</div>
							
							<i class="corner-f8-10 tl"></i>
							<i class="corner-f8-10 tr"></i>
							<i class="corner-f8-10 br"></i>
							<i class="corner-f8-10 bl"></i>
						</div>
					</xsl:if>
					
					<div class="block">
						<div class="header">Облако тегов</div>
						<div class="content tags">
							<xsl:apply-templates select="document('xmodule://photos/getTagsCloud')/data/response/tags" mode="block-tags-cloud" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
				</div>

				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
		<xsl:choose>
			<xsl:when test="$method = 'album'">
				<xsl:apply-templates select="document(concat('xobject://photoalbum/', @album-id))/data/object" mode="album-bar" />
			</xsl:when>
			<xsl:when test="../@method = 'tag'">
				<div class="tag-search">
					<form action="{$baseURI}/photos/tag/go" method="post">
						<input id="tag_name" class="tag-name" type="text" name="tag">
							<xsl:attribute name="value">
								<xsl:value-of select="@tag-filter" />
							</xsl:attribute>
						</input>
						<xsl:text> </xsl:text>
						<input type="submit" value="→" />
					</form>
				</div>
				<script type="text/javascript">
					$('#tag_name')
						.blur (function () {
							if ($(this).val() == '') {
								$(this)
									.val('Введите тег')
									.css('color', '#dfdfdf');
							}
						})
						.click (function () {
							if ($(this).val() == 'Введите тег') {
								$(this)
									.val('')
									.css ('color', '#000');
							}
						});
					
					
					if ($('#tag_name').val() == '') {
						$('#tag_name')
							.val('Введите тег')
							.css('color', '#dfdfdf');
					}
				</script>
			</xsl:when>
			
			<xsl:otherwise>
				<h1>Фотографии: последние поступления</h1>
			</xsl:otherwise>
		</xsl:choose>
		
		<xsl:if test="count(object) = 0">
			<div class="simple-message">
				<xsl:text>Увы, здесь фотографий нет.</xsl:text>
				<xsl:if test="$method = 'album' and @album-owner-id = $userId">
					<xsl:text> </xsl:text>
					<input type="button" value="Загрузить фотографии" onclick="document.location.href='{$baseURI}/photos/upload/{@album-id}'" />
				</xsl:if>
			</div>
		</xsl:if>
		
		<xsl:if test="count(object) != 0">
			<div class="photos-list">
				<xsl:apply-templates select="object" />
			</div>
		</xsl:if>
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
					<xsl:if test="../@method != 'album'">
						<xsl:value-of select="concat ($baseURI, '/photos')" />
					</xsl:if>
					<xsl:if test="../@method = 'album'">
						<xsl:value-of select="concat ($baseURI, '/photoalbum/', @album-id)" />
					</xsl:if>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type='photo']">
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="description" select="php:functionString ('XSLTDotsString', property[@name='description']/value, 200)" />
		<xsl:param name="photo" select="property[@name='photo']/value" />
		<xsl:param name="albumId" select="property[@name='album_id']/value" />
		<xsl:param name="rating" select="number(property[@name='rating']/value)" />		
		
		<div class="item">
			<div class="photo">
				<a href="{$baseURI}/photo/{@id}">
					<img alt="" src="{$baseURI}/thumb_100_100{$photo}" />
				</a>
			</div>
			
			<div class="owner">
				<a class="user" href="{$baseURI}/user/{$userLogin}">
					<xsl:value-of select="$userLogin" />
				</a>
				
				<span class="date">
					<xsl:value-of select="property[@name='date']/value" />
				</span>
			</div>
			
			<div class="controls">
				<a class="comments" href="{$baseURI}/photo/{@id}#comments" title="Комментарии">
					<xsl:value-of select="property[@name='count_comments']/value" />
				</a>
				<span class="rating" title="Рейтинг">
					<xsl:value-of select="$rating" />
				</span>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>